package view;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

import controller.SalesCardController;
import entity.Commissioned;
import entity.SalesCard;
import entity.TimeCard;

@ManagedBean
@ViewScoped
public class ListOfSalesCards {
	@Inject
	SalesCardController controller;
	private List<SalesCard> listSalesCards;
	private List<SalesCard> deleteSalesCard=new ArrayList<SalesCard>();
	@PostConstruct
	public void loadList() {
		FacesContext context = FacesContext.getCurrentInstance();
		Login login = (Login) context.getExternalContext().getSessionMap()
				.get("login");

		listSalesCards = controller.listOfAllSalesCards((Commissioned) login
				.getEmployee());
	}


	public List<SalesCard> getListSalesCards() {
		return listSalesCards;
	}

	public void setListSalesCards(List<SalesCard> ListSalesCards) {
		listSalesCards = ListSalesCards;
	}
	public void AddListDeletedSalesCard( SalesCard card){
		if(!deleteSalesCard.contains(card)){
			deleteSalesCard.add(card);
		}else{
			deleteSalesCard.remove(card);
		}
	}
	public String DeleteSalesCards(){
		for(int i=0;i<deleteSalesCard.size();i++){
			int value=controller.deleteSalesCard(deleteSalesCard.get(i));
			}
		deleteSalesCard.clear();
		return "ListSalesCard?faces-redirect=true";
	}
}
